<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>

<!-- 导入公共的jquery.js -->
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>

<!-- 导入layui.js -->
<script src="./layui/layui.js"></script>

<body>
<center>
    <h1>添加歌曲</h1>

    <form class="layui-form" action="/musicUploadServlet.action">

        <!-- 参数作为隐藏域传给后台 -->
        <input type="hidden" name="param" value="add">

        <div class="layui-form-item">
            <label class="layui-form-label">歌曲名称</label>
            <div class="layui-input-block">
                <input type="text" name="musicName" required  lay-verify="required" placeholder="请输入歌曲名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">专辑名称</label>
            <div class="layui-input-inline">
                <input type="text" name="musicAlbumName" required lay-verify="required" placeholder="请输入专辑名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">专辑图片</label>

            <div class="layui-upload-drag" id="test10">
                <i class="layui-icon"></i>
                <p>点击上传，或将文件拖拽到此处</p>
                <div class="layui-hide" id="uploadDemoView">
                    <hr>
                    <img src="" alt="上传成功后渲染" style="max-width: 196px">
                </div>
            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">歌曲音频</label>
            <div class="layui-input-inline">
                <input type="text" name="musicMp3url" required lay-verify="required" placeholder="请输入歌曲音频地址" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">歌手</label>
            <div class="layui-input-inline">
                <input type="text" name="musicArtistName" required lay-verify="required" placeholder="请输入歌手名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">指定歌单</label>
            <div class="layui-input-block">
                <select name="sheetId" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="1">热歌榜</option>
                    <option value="2">新歌榜</option>
                    <option value="3">原创榜</option>
                    <option value="4">我的喜欢</option>
                    <option value="5">老歌榜</option>
                    <option value="6">翻唱榜</option>
                    <option value="7">飙升榜</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>
        //Demo
        layui.use('form', function(){
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function(data){
                layer.msg(JSON.stringify(data.field));
                //前端可以做一些校验
                return true;//true表示继续向下执行,false表示不执行
            });
        });
    </script>


</center>
</body>

<script>
    layui.use(['upload', 'element', 'layer'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,element = layui.element
            ,layer = layui.layer;

        //拖拽上传
        upload.render({
            elem: '#test10'
            ,url: 'musicUploadServlet.action?param=upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            ,done: function(res){//res就是我们后台返给前端的map集合
                layer.msg('上传成功');
                layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data);
                console.log(res)
            }
        });
    });
</script>



</html>